package cn.dglydrpy.study.ssm.common.rabbitmq.xml;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.UnsupportedEncodingException;

public class RabbitXMLConsumer {

    public static void main(String[] args) throws UnsupportedEncodingException {
    	
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-rabbit-consumer.xml");

        final RabbitTemplate template = context.getBean(RabbitTemplate.class);

        while (true) {
        	 final Message message = template.receive("queue.ssm.rabbit");
        	 if(message != null) {
            	 // 拉消息模式
                System.out.println("RabbitXMLConsumer接收到消息：" + new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
//                System.out.println(new String(message.getBody(), "utf-8"));
            }else {
            	break;
            }
        }
 
//        context.close();
    }

}
